package component.scroll;

import javax.swing.*;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;

/**
  * @Description 鼠标滚轮滚动事件封装
  * @author 孔明浩
  * @Date 2020/3/31
  */
public class SmallMouseWheelListener implements MouseWheelListener {
    final int move;
    final JScrollBar scrollBar;
    /**
     * @Description
     * @param move 每一个滚动事件滚动的步幅
     * @param scrollBar 滚动事件操控的scrollBar
     * @author 孔明浩
     * @Date 2020/3/31
     */
    public SmallMouseWheelListener(int move, JScrollBar scrollBar){
        this.move = move;
        this.scrollBar = scrollBar;
    }
    @Override
    public void mouseWheelMoved(MouseWheelEvent e) {
        if (e.getWheelRotation() == 1){
            scrollBar.setValue(scrollBar.getValue() + move);
        } else if (e.getWheelRotation() == -1){
            scrollBar.setValue(scrollBar.getValue() - move);
        }
    }
}
